package com.janlei.acc.strategy;

import java.util.HashMap;

/**
 * 策略模式
 */
public class StrategyStu {
}

/**
 * 策略接口
 */
interface Strategy {
    void archive();
}

/**
 * 具体实现caseA
 */
class CaseA implements Strategy {

    @Override
    public void archive() {
        System.out.println("具体实现caseA");
    }
}

/**
 * 具体实现caseB
 */
class CaseB implements Strategy {

    @Override
    public void archive() {
        System.out.println("具体实现caseB");
    }
}

class Context {
    Strategy strategy;

    public Context(Strategy strategy) {
        this.strategy = strategy;
    }

    /**
     * 上下文接口
     */
    public void contextInterface() {
        strategy.archive();
    }
}

class ContextList {
    private final HashMap<String, Strategy> hashMap;

    {
        hashMap = new HashMap<>();
        hashMap.put("A", new CaseA());
        hashMap.put("B", new CaseB());
    }

    public Strategy getKindOfCase(String kind) {
        return hashMap.get(kind);
    }
}